{% extends "base.html" %}

{% block content %}
<div class="row">
    <div class="col-md-12 mb-4">
        <div class="d-flex justify-content-between align-items-center">
            <h2>技能标签列表</h2>
            {% if current_user.is_admin() %}
            <a href="{{ url_for('skills.create') }}" class="btn btn-primary">添加技能标签</a>
            {% endif %}
        </div>
    </div>
</div>

<div class="row">
    <div class="col-md-12">
        <div class="card">
            <div class="card-header bg-primary text-white">
                <h5 class="mb-0">所有技能标签</h5>
            </div>
            <div class="card-body">
                {% if skills %}
                <div class="table-responsive">
                    <table class="table table-hover">
                        <thead>
                            <tr>
                                <th>技能名称</th>
                                <th>拥有此技能的成员</th>
                                <th>相关文章</th>
                                {% if current_user.is_admin() %}
                                <th>操作</th>
                                {% endif %}
                            </tr>
                        </thead>
                        <tbody>
                            {% for skill in skills %}
                            <tr>
                                <td>{{ skill.name }}</td>
                                <td>
                                    <a href="{{ url_for('skills.users', skill_id=skill.id) }}" class="badge bg-info text-decoration-none">
                                        {{ skill.users|length }} 名成员
                                    </a>
                                </td>
                                <td>
                                    <a href="{{ url_for('articles.by_skill', skill_id=skill.id) }}" class="badge bg-info text-decoration-none">
                                        {{ skill.articles|length }} 篇文章
                                    </a>
                                </td>
                                {% if current_user.is_admin() %}
                                <td>
                                    <a href="{{ url_for('skills.edit', skill_id=skill.id) }}" class="btn btn-sm btn-outline-primary">编辑</a>
                                    <a href="{{ url_for('skills.delete', skill_id=skill.id) }}" class="btn btn-sm btn-outline-danger" onclick="return confirm('确定要删除此技能标签吗？');">删除</a>
                                </td>
                                {% endif %}
                            </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </div>
                {% else %}
                <p class="text-muted">暂无技能标签</p>
                {% endif %}
            </div>
        </div>
    </div>
</div>
{% endblock %}